/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {boolean}
 */
var checkTree = function(root) {
  let result = true;
  function preView(node) {
    if(!node || !result || (!node.left && !node.right)) return;
    let left = 0, right = 0;
    if(node.left) {
      left = node.left.val;
    }
    if(node.right) {
      right = node.right.val;
    }
    if(node.val != left + right) {
      result = false;
    }
    if(node.left) preView(node.left);
    if(node.right) preView(node.right);
  }
  preView(root);
  return result;
};
